public class ExceptionHandlerMethodResolver
extends java.lang.Object
ExceptionHandler
methods at initialization, finds
the best matching method mapped to an exception at runtime.
Exception mappings are extracted from the method @ExceptionHandler
annotation or by looking for Throwable
method arguments.
Modifier and Type | Field and Description |
---|---|
static ReflectionUtils.MethodFilter |
EXCEPTION_HANDLER_METHODS
A filter for selecting @
ExceptionHandler methods. |
private java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> |
exceptionLookupCache |
private java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> |
mappedMethods |
private static java.lang.reflect.Method |
NO_METHOD_FOUND |
Constructor and Description |
---|
ExceptionHandlerMethodResolver(java.lang.Class<?> handlerType)
A constructor that finds
ExceptionHandler methods in a handler. |
Modifier and Type | Method and Description |
---|---|
private void |
addExceptionMapping(java.lang.Class<? extends java.lang.Throwable> exceptionType,
java.lang.reflect.Method method) |
private java.util.List<java.lang.Class<? extends java.lang.Throwable>> |
detectMappedExceptions(java.lang.reflect.Method method)
Detect the exceptions an @
ExceptionHandler method is mapped to. |
private java.lang.reflect.Method |
getMappedMethod(java.lang.Class<? extends java.lang.Exception> exceptionType)
Return the method mapped to the exception type, or
null . |
private void |
init(java.util.Set<java.lang.reflect.Method> exceptionHandlerMethods) |
java.lang.reflect.Method |
resolveMethod(java.lang.Exception exception)
Find a method to handle the given exception.
|
private static final java.lang.reflect.Method NO_METHOD_FOUND
private final java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> mappedMethods
private final java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.reflect.Method> exceptionLookupCache
public static final ReflectionUtils.MethodFilter EXCEPTION_HANDLER_METHODS
ExceptionHandler
methods.public ExceptionHandlerMethodResolver(java.lang.Class<?> handlerType)
ExceptionHandler
methods in a handler.handlerType
- the handler to inspect for exception handler methods.java.lang.IllegalStateException
- If an exception type is mapped to two methods.java.lang.IllegalArgumentException
- If an @ExceptionHandler
method is not mapped to any exceptions.private void init(java.util.Set<java.lang.reflect.Method> exceptionHandlerMethods)
private java.util.List<java.lang.Class<? extends java.lang.Throwable>> detectMappedExceptions(java.lang.reflect.Method method)
ExceptionHandler
method is mapped to.
If the method @ExceptionHandler
annotation doesn't have any,
scan the method signature for all arguments of type Throwable
.private void addExceptionMapping(java.lang.Class<? extends java.lang.Throwable> exceptionType, java.lang.reflect.Method method)
public java.lang.reflect.Method resolveMethod(java.lang.Exception exception)
ExceptionDepthComparator
.exception
- the exceptionExceptionHandler
method, or null
private java.lang.reflect.Method getMappedMethod(java.lang.Class<? extends java.lang.Exception> exceptionType)
null
.